/*
 * @filename JsonConverter.java
 * @author barry
 * @version 0.0.1
 * @date 2020年3月26日
 */
package com.bnzj.core.persistence.convert;

import javax.persistence.AttributeConverter;

import com.bnzj.core.util.JsonUtils;
import com.fasterxml.jackson.databind.JsonNode;

/**
 * JSON字段类型转换器
 * @author barry
 * @date 2020-03-26
 * @see javax.persistence.Convert
 */
public class JsonConverter implements AttributeConverter<JsonNode, String> {

    @Override
    public String convertToDatabaseColumn(JsonNode attribute) {
        return attribute.toString();
    }

    @Override
    public JsonNode convertToEntityAttribute(String dbData) {
        return JsonUtils.valueToTree(dbData);
    }

}
